using System.IO;
using System.Runtime.Serialization.Formatters.Binary;
using NUnit.Framework;
using Wax;

namespace WaxLibTest
{
    /// <summary>
    /// Test the behavior of the <see cref="InvalidCommandException"/> class.
    /// </summary>
    [TestFixture]
    public class InvalidCommandExceptionTest
    {
        /// <summary>
        /// Test that we can serialize and deserialize an instance of <see cref="InvalidCommandException"/>.
        /// </summary>
        [Test]
        public void Serialize()
        {
            string message = "Invalid command";
            string commandName = "CMDUNKNOWN";
            InvalidCommandException invalidCommandException = new InvalidCommandException(message, commandName);

            using (Stream memory = new MemoryStream())
            {
                BinaryFormatter formatter = new BinaryFormatter();
                formatter.Serialize(memory, invalidCommandException);
                memory.Position = 0; // Reset stream position
                invalidCommandException = (InvalidCommandException)formatter.Deserialize(memory);
            }

            Assert.IsNotNull(invalidCommandException, "InvalidCommandException object was not serialized properly.");
            Assert.AreEqual(message, invalidCommandException.Message);
            Assert.AreEqual(commandName ,invalidCommandException.InvalidCommandName);            
        }
    }
}